#include <yaml-cpp/yaml.h>
#include <iostream>
#include <QtDebug>
#include <QDir>

int main() {
    try {
        qDebug() << QDir::currentPath();
        // 加载YAML配置文件
        YAML::Node config = YAML::LoadFile("config.yaml");
        // 检查是否成功加载配置文件
        if (config.IsNull()) {
            qDebug() << "Failed to load config.yaml" ;
            return 1;
        }

        // 访问配置数据
        std::string serverAddress = config["server"]["address"].as<std::string>();
        int serverPort = config["server"]["port"].as<int>();
        std::string username = config["user"]["name"].as<std::string>();
        int age = config["user"]["age"].as<int>();

        // 打印配置数据
        std::cout << "Server Address: " << serverAddress << std::endl;
        std::cout << "Server Port: " << serverPort << std::endl;
        std::cout << "Username: " << username << std::endl;
        std::cout << "Age: " << age << std::endl;
    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }

    return 0;
}
